home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / program / cwaudit.zip / CW_APPS.PAS next >
Pascal/Delphi Source File  |  1996-05-21  |  5KB  |  154 lines

  1. {
  2.   Author:    Craig Ward
  3.   Copyright: none - public domain
  4.  
  5.   Date:      20/5/96
  6.  
  7.   Version:   1.0
  8.  
  9.   Overview:  Common utilities, common constants, and other misc. information.
  10.  
  11.   Notes:     WinExecAndWait, though useful in most cases, will not work efficately if used
  12.              to execute Setup programmes which launch a "child" setup routine themselves. An
  13.              example would be the installation programmes for the BDE and ReportSmith
  14.              which both, once initiated, spawn a child program (which runs from the
  15.              hard-disk).
  16. ********************************************************************************}
  17. unit Cw_apps;
  18.  
  19. interface
  20.  
  21. uses
  22.  WinTypes, WinProcs, Messages, Dialogs, SysUtils, IniFiles, WinDos,
  23.  DBiTypes;
  24.  
  25.  
  26.  
  27. {***constants*******************************************************************}
  28.  
  29. {file-system constants}
  30. const
  31.  fsMaxDir =            fsDirectory + 1;     {maximum length of directory, plus null}
  32.  fsMaxFullFileName =   fsPathName + 1;      {maximum length of path\file-name, plus null}
  33.  fsMaxFileName =       fsFileName + 1;      {maximum length of a file-name, not inc. ext.}
  34.  fsMaxFileNameExt =    fsFileName + fsExtension +1; {maximum lenght of a file-name, inc. extension}
  35.  fsString =            256;                 {chosen length of a string allocation, inc. null}
  36.  fsWinBuffer =         144;                 {minimum length of buffer for Windows directory}
  37.  
  38.  
  39. {database constants}
  40. const
  41.  dbAlias =             DBiMaxNameLen + 1;   {maximum length of an ALIAS name plus null}
  42.  dbTable =             fsFileName + 1;      {maximum length of a table-name plus null}
  43.  
  44.  
  45.  
  46.  
  47. {***custom routines*************************************************************}
  48.  
  49. {prototypes}
  50. function mWinExecAndWait(Path: PChar; Visibility: word): word;
  51. procedure mCheckWinExec(i: integer);
  52.  
  53.  
  54.  
  55.  
  56.  
  57. implementation
  58.  
  59.  
  60.  
  61. {***executing programs**********************************************************}
  62.  
  63. {execute program and wait for termination -
  64.  this routine was downloaded from an un-named source on Compuserve}
  65. function mWinExecAndWait(Path: PChar; Visibility: word): word;
  66. var
  67.  InstanceID: THandle;
  68.  Msg: TMsg;
  69. begin
  70.  InstanceID := WinExec(Path,Visibility);
  71.  if InstanceID < 32 then {a value less than 32 indiciates an Exec error}
  72.   begin
  73.    mCheckWinExec(InstanceID);
  74.   end
  75.  else
  76.   Repeat
  77.    while PeekMessage(Msg,0,0,0,PM_REMOVE) do
  78.     begin
  79.      if Msg.Message = WM_QUIT then
  80.       halt(Msg.wParam);
  81.       TranslateMessage(Msg);
  82.       DispatchMessage(Msg);
  83.     end;
  84.   until GetModuleUsage(InstanceID) = 0
  85. end;
  86.  
  87.  
  88. {switch on returned error value, and display text}
  89. procedure mCheckWinExec(i: integer);
  90. var
  91.  s: ^string;
  92. begin
  93.  try
  94.   New(s);
  95.  
  96.  case i of
  97.   0:
  98.    s^ := 'System was out of memory, executable file was corrupt'+#13#10+
  99.          'or relocations were invalid.';
  100.   2:
  101.    s^ := 'File was not found.';
  102.   3:
  103.    s^ := 'Path was not found.';
  104.   5:
  105.    s^ := 'Attempt was made to dynamically link to a task,'+#13#10+
  106.          'or there was a sharing or network-protection error.';
  107.   6:
  108.    s^ := 'Library required separate data segments for each task.';
  109.   8:
  110.    s^ := 'There was insufficient memory to start the application.';
  111.   10:
  112.    s^ := 'Windows version was incorrect.';
  113.   11:
  114.    s^ := 'Executable file was invalid. Either it was not'+#13#10+
  115.          'a Windows application or there was an error in'+#13#10+
  116.          'the .EXE image.';
  117.   12:
  118.    s^ := 'Application was designed for a different operating'+#13#10+
  119.          'system.';
  120.   13:
  121.    s^ := 'Application was designed for MS-DOS 4.0.';
  122.   14:
  123.    s^ := 'Type of executable file was unknown.';
  124.   15:
  125.    s^ := 'Attempt was made to load a real-mode application'+#13#10+
  126.          '(developed for an earlier version of Windows).';
  127.   16:
  128.    s^ := 'Attempt to load second instance of an executable'+#13#10+
  129.          'containing multiple data segments not marked read-only.';
  130.   19:
  131.    s^ := 'Attempt was made to load a compressed executable file.'+#13#10+
  132.          'The file must be decompressed before it can be loaded.';
  133.   20:
  134.    s^ := 'Dynamic-link library (DLL) file was invalid. One of the'+#13#10+
  135.          'DLLs required to run this application was corrupt.';
  136.   21:
  137.    s^ := 'Application requires 32-bit extensions.';
  138.  end;
  139.   messageDlg('Error in execution of program: '+#13#10+#13#10+s^,mtWarning,[mbOK],0);
  140.  
  141.  finally
  142.   Dispose(s);
  143.  end;
  144.  
  145. end;
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152. {}
  153. end.
  154.